package exam;

/**
 * @author: bamboo_shoot
 * @date: 20/2/7 1:24
 * @description: 模仿老师的test02写
 * 数组中只出现一次的元素有2个
 */
public class Imitation {
    public static void main(String[] args) {
        int[] arr = {1, 3, 4, 5, 0, 0, 6, 6, 0, 5, 4, 7, 6, 7, 0, 5};
//        这个是返回的统计只有1次的次数
        int times = getNumberOfTimes(arr);
        System.out.println("数组中只出现一次的元素有" + times + "个");
    }

    private static int getNumberOfTimes(int[] arr) {
//        这里要统计每一个数的次数
        int index = 0;
        for (int i = 0; i < arr.length; i++) {
            int count = getCount(arr, arr[i]);
            if (count == 1) {
                index++;
            }
        }
        return index;
    }

    private static int getCount(int[] arr, int num) {
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == num) {
                count++;
            }
        }
        return count;
    }

}
